package com.wuxiaoqin.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wuxiaoqin.admin.entity.Users;
import com.wuxiaoqin.admin.mapper.UsersMapper;
import com.wuxiaoqin.admin.service.IUsersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wuxiaoqin.uitls.respObj.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2021-11-10
 */
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements IUsersService {

    @Autowired
    private UsersMapper usersMapper;
    @Override
    public RespBean selectUserCount() {
        Integer integer = usersMapper.selectCount(new QueryWrapper<Users>());
        return RespBean.success("会员个数为：",integer);
    }

    @Override
    public Page<Users> selectUserPage(Integer page, Integer size) {
        Page<Users> usersPage = new Page<>(page, size);
        Page<Users> usersPage1 = usersMapper.selectPage(usersPage, new QueryWrapper<Users>().select(
                "U_id", "U_phone", "U_name", "U_sex",
                "U_mail", "U_points", "U_signature", "U_state", "U_createTime"));
        return usersPage1;
    }

    @Override
    public RespBean deleteUser(Integer userId) {
        int i = usersMapper.deleteById(userId);
        if (i<=0){
            return RespBean.error("删除失败");
        }
        return RespBean.success("删除成功");
    }


}
